package com.ruoyi.vip.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.vip.domain.VipRecharge;
import com.ruoyi.vip.service.IVipRechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员充值Controller
 *
 * @author ruoyi
 * @date 2021-04-20
 */
@RestController
@RequestMapping("/vip/recharge")
public class VipRechargeController extends BaseController
{
    @Autowired
    private IVipRechargeService vipRechargeService;

    /**
     * 查询会员充值列表
     */
    @PreAuthorize("@ss.hasPermi('vip:recharge:list')")
    @GetMapping("/list")
    public TableDataInfo list(VipRecharge vipRecharge)
    {
        startPage();
        List<VipRecharge> list = vipRechargeService.selectVipRechargeList(vipRecharge);
        return getDataTable(list);
    }

    /**
     * 导出会员充值列表
     */
    @PreAuthorize("@ss.hasPermi('vip:recharge:export')")
    @Log(title = "会员充值", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VipRecharge vipRecharge)
    {
        List<VipRecharge> list = vipRechargeService.selectVipRechargeList(vipRecharge);
        ExcelUtil<VipRecharge> util = new ExcelUtil<VipRecharge>(VipRecharge.class);
        return util.exportExcel(list, "recharge");
    }

    /**
     * 获取会员充值详细信息
     */
    @PreAuthorize("@ss.hasPermi('vip:recharge:query')")
    @GetMapping(value = "/{rechargeId}")
    public AjaxResult getInfo(@PathVariable("rechargeId") Long rechargeId)
    {
        return AjaxResult.success(vipRechargeService.selectVipRechargeById(rechargeId));
    }

    /**
     * 新增会员充值
     */
    @PreAuthorize("@ss.hasPermi('vip:recharge:add')")
    @Log(title = "会员充值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VipRecharge vipRecharge)
    {
        return toAjax(vipRechargeService.insertVipRecharge(vipRecharge));
    }

    /**
     * 修改会员充值
     */
    @PreAuthorize("@ss.hasPermi('vip:recharge:edit')")
    @Log(title = "会员充值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VipRecharge vipRecharge)
    {
        return toAjax(vipRechargeService.updateVipRecharge(vipRecharge));
    }

    /**
     * 删除会员充值
     */
    @PreAuthorize("@ss.hasPermi('vip:recharge:remove')")
    @Log(title = "会员充值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rechargeIds}")
    public AjaxResult remove(@PathVariable Long[] rechargeIds)
    {
        return toAjax(vipRechargeService.deleteVipRechargeByIds(rechargeIds));
    }
}
